Addon for Workflow Nodes Update Check Template

工作流概述

这是一个包含16个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "xlMrGt0c1eFi4J1U",
  "meta": {
    "instanceId": "fb8bc2e315f7f03c97140b30aa454a27bc7883a19000fa1da6e6b571bf56ad6d",
    "templateCredsSetupCompleted": true
  },
  "name": "Addon for Workflow Nodes Update Check Template",
  "tags": [],
  "nodes": [
    {
      "id": "e8068a93-5474-474e-a48e-947269b7ca5f",
      "name": "Execute Workflow Trigger",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        860,
        1140
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "9b4524d8-6ded-489b-bf45-6810f5306652",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        120
      ],
      "parameters": {
        "color": 5,
        "width": 1316.8621045610755,
        "height": 887.980239951363,
        "content": "## Download the main workflow and connect it's output to this workflow
- Download this workflow and follow the belonging instructions: [https://n8n.io/workflows/2301-check-if-workflows-contain-build-in-nodes-that-are-not-of-the-latest-version/](https://n8n.io/workflows/2301-check-if-workflows-contain-build-in-nodes-that-are-not-of-the-latest-version/)
- Add an \"Execute Workflow\" node and configure it, so it calls this workflow.
  
![Image](https://i.imgur.com/y0vPhYz.png#full-width)"
      },
      "typeVersion": 1
    },
    {
      "id": "cb0cacc1-34d0-4e4d-a7db-e44ece1a155f",
      "name": "Prepare Output",
      "type": "n8n-nodes-base.set",
      "position": [
        2180,
        1140
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "26c2bf59-2051-47e3-a6bf-3896ad427404",
              "name": "name",
              "type": "string",
              "value": "=<a href={{ $('Settings').item.json.instanceBaseUrl }}/workflow/{{ $json.id }}>{{ $json.name }}</a>"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "4b914937-1cff-4fc2-886b-64ec6818daf3",
      "name": "Send Summary",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2400,
        1140
      ],
      "webhookId": "1ad759b3-f1cd-49dd-b288-e3344fa94c8a",
      "parameters": {
        "message": "=These workflows contain outdated nodes:<br>
<ul>
{{ $('Prepare Output').all().pluck('json').pluck('name').map(item => \"<li>\"+item+\"</li>\").join('') }}
</ul>",
        "options": {
          "appendAttribution": false
        },
        "subject": "Outdated n8n Workflow Nodes"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "TWM2BLjDHQtGAFQn",
          "name": "Gmail (octionicsolutions)"
        }
      },
      "executeOnce": true,
      "typeVersion": 2.1
    },
    {
      "id": "2f259d45-cb31-4007-beb0-93123cc619c3",
      "name": "Get Workflow",
      "type": "n8n-nodes-base.n8n",
      "position": [
        1520,
        1140
      ],
      "parameters": {
        "operation": "get",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Start Reference').item.json.Id }}"
        },
        "requestOptions": {}
      },
      "credentials": {
        "n8nApi": {
          "id": "fRyEJuhN9Nf3aQap",
          "name": "n8n account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e2bbfc5b-1af6-43b1-9d03-f35b5837d3cc",
      "name": "Update Workflow",
      "type": "n8n-nodes-base.n8n",
      "position": [
        1960,
        1140
      ],
      "parameters": {
        "operation": "update",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "requestOptions": {},
        "workflowObject": "={{ JSON.stringify($json) }}"
      },
      "credentials": {
        "n8nApi": {
          "id": "fRyEJuhN9Nf3aQap",
          "name": "n8n account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f2bb0529-6e38-46c6-93e8-de76e9ecc31e",
      "name": "Modify Workflow (if required)",
      "type": "n8n-nodes-base.code",
      "position": [
        1740,
        1140
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "let symbol = $('Settings').item.json.symbol;
let onlyMajorChanges = $('Settings').item.json.onlyMajorChanges;
let addNodesToCanvas = $('Settings').item.json.addNodesToCanvas;

// create shallow copy including nested objects
let data = JSON.parse(JSON.stringify($json));

changeCount = 0;
// Loop through nodes and update the names
for (let outdatedNode of $('Start Reference').item.json.outdated_nodes) {
  // skip minor changes, if settings require it
  if (onlyMajorChanges && outdatedNode.version.toString().substring(0, 1) == outdatedNode.latestVersion.toString().substring(0, 1)) {
    continue;
  }
  // update nodes, it they are not already renamed with symbol
  for (let existingNode of data.nodes) {
    if (outdatedNode.name == existingNode.name && !existingNode.name.startsWith(symbol) && existingNode.id) {
      // prepend new nodes, so they appear below outdated nodes on the canvas
      if (addNodesToCanvas) {
        let newNode = JSON.parse(JSON.stringify(existingNode));
        delete newNode.id;
        newNode.typeVersion = outdatedNode.latestVersion;
        newNode.position = [newNode.position[0] + 40, newNode.position[1] - 40];
        data.nodes.unshift(newNode);
      }
      // rename outdated nodes (prepend symbol)
      existingNode.name = symbol + \" \" + existingNode.name;
    
      // update connections
      for (let connectionKey in data.connections) {
        let connection = data.connections[connectionKey];
      
        // rename keys
        if (connectionKey == outdatedNode.name) {
          let newKey = symbol + \" \" + connectionKey;
          data.connections[newKey] = connection;
          delete data.connections[connectionKey];
        }
      
        // check the nested \"main\" array
        if (connection.main) {
          for (let mainArray of connection.main) {
            for (let nodeObj of mainArray) {
              if (nodeObj.node == outdatedNode.name) {
                nodeObj.node = symbol + \" \" + nodeObj.node;
              }
            }
          }
        }
      }
      changeCount++;
    }
  }
}

if (changeCount == 0) {
  return null;
}

return {
  id: data.id,
  name: data.name,
  nodes: data.nodes,
  connections: data.connections,
  settings: data.settings
}"
      },
      "typeVersion": 2
    },
    {
      "id": "b4b7d328-8128-4f07-841a-1efa26c3fdd5",
      "name": "Start Reference",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1080,
        1140
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "7d80b557-15ac-479e-a219-dd254580a063",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        1020
      ],
      "parameters": {
        "color": 7,
        "width": 216.6228464570463,
        "height": 282.1449413577448,
        "content": "This workflow is called by another workflow which provides a list of all workflows with major and minor node updates"
      },
      "typeVersion": 1
    },
    {
      "id": "1becaab6-fe2a-44e9-bc7e-ce87665f25bd",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2120,
        680
      ],
      "parameters": {
        "color": 7,
        "width": 435.46822963832705,
        "height": 327.68691689762716,
        "content": "## Example input data

```
[
  {
    \"workflow\": \"Workflow Nodes Update\",
    \"Id\": \"dFJpQTFg3QPH6Ol9\",
    \"outdated_nodes\": [
      {
        \"name\": \"If\",
        \"type\": \"n8n-nodes-base.if\",
        \"version\": 2,
        \"latestVersion\": 2.2
      }
    ]
  }
]
```"
      },
      "typeVersion": 1
    },
    {
      "id": "9ce81677-4dd4-4a9a-a7a3-66b113c69de6",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1020,
        1020
      ],
      "parameters": {
        "color": 7,
        "width": 216.6228464570463,
        "height": 282.1449413577448,
        "content": "The following nodes start referencing from here, so it is easily possible to change the logic prior to this node."
      },
      "typeVersion": 1
    },
    {
      "id": "f6e7e7ce-1282-4292-8675-ca8bbe215d5f",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1240,
        1020
      ],
      "parameters": {
        "width": 216.6228464570463,
        "height": 282.1449413577448,
        "content": "## Update settings
Minimum requirement:
- Set your instanceBaseUrl"
      },
      "typeVersion": 1
    },
    {
      "id": "46b168d5-c866-497b-8664-92722a356feb",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "position": [
        1300,
        1140
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "99947a54-e9f9-4d04-b273-9d7eeed62775",
              "name": "instanceBaseUrl",
              "type": "string",
              "value": "http://localhost:5432"
            },
            {
              "id": "35a63bda-fcbb-4885-a8d6-4b52c6579206",
              "name": "symbol",
              "type": "string",
              "value": "⚠️"
            },
            {
              "id": "3481286b-359f-4e86-8f56-bdb267ebd6a2",
              "name": "onlyMajorChanges",
              "type": "boolean",
              "value": true
            },
            {
              "id": "2377c274-5501-494f-813e-0d3ebe47e375",
              "name": "addNodesToCanvas",
              "type": "boolean",
              "value": true
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d28ac933-7dbc-4039-821b-7cd4c4c5ec94",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2120,
        1020
      ],
      "parameters": {
        "color": 7,
        "width": 216.6228464570463,
        "height": 282.1449413577448,
        "content": "URL's are generated for each affected workflow"
      },
      "typeVersion": 1
    },
    {
      "id": "0fef2be5-92d5-4d4f-8afc-b958ee616787",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2340,
        1020
      ],
      "parameters": {
        "width": 216.6228464570463,
        "height": 282.1449413577448,
        "content": "## Setup Gmail
Minimum requirement:
- Update mail recipient"
      },
      "typeVersion": 1
    },
    {
      "id": "dc940f78-1eff-4393-9d9a-f4afefe24d45",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1460,
        1020
      ],
      "parameters": {
        "color": 7,
        "width": 657.2496253932529,
        "height": 282.1449413577448,
        "content": "Each workflow is being processed and modified if needed. Depending on the settings an icon is being prepended to the name of outdated nodes. In addition a newer version is being added close by, so it can be replaced quicker by the user."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "f4bb34b0-7561-4d77-beac-8f6988a0ed64",
  "connections": {
    "Settings": {
      "main": [
        [
          {
            "node": "Get Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Workflow": {
      "main": [
        [
          {
            "node": "Modify Workflow (if required)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Output": {
      "main": [
        [
          {
            "node": "Send Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start Reference": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Workflow": {
      "main": [
        [
          {
            "node": "Prepare Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Workflow Trigger": {
      "main": [
        [
          {
            "node": "Start Reference",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Modify Workflow (if required)": {
      "main": [
        [
          {
            "node": "Update Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • Executeworkflowtrigger
  • Stickynote
  • Set
  • Gmail
  • N8N

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作